package com.test.loop;

public class WhileTest4 {
    public static void main(String[] args) {
        double money = 100000;
        double rate = 0.017;
        double earnings = 2 * money;

        int year = calcYears(money, rate, earnings);
        System.out.println("需要 " + year + " 年，存款金额才能翻倍");
    }

    public static int calcYears(double money,double rate,double earnings) {
        int year = 0;
        while(money<earnings) {
            money += money * rate;
            year++;
        }
        return year;
    }
}
